3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * class to represent the actions that can be performed on a group of contacts
38 * used by the search forms
41 class CRM_Contact_Task
{
51 HOUSEHOLD_CONTACTS
= 9,
52 ORGANIZATION_CONTACTS
= 10,
56 SAVE_SEARCH_UPDATE
= 14,
61 PRINT_FOR_CONTACTS
= 19,
66 DELETE_PERMANENTLY
= 24,
67 COMMUNICATION_PREFS
= 25;
74 static $_tasks = NULL;
77 * The optional task array
81 static $_optionalTasks = NULL;
83 public static function initTasks() {
85 self
::$_tasks = array(
86 self
::GROUP_CONTACTS
=> array(
87 'title' => ts('Add Contacts to Group'),
88 'class' => 'CRM_Contact_Form_Task_AddToGroup',
90 self
::REMOVE_CONTACTS
=> array(
91 'title' => ts('Remove Contacts from Group'),
92 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
94 self
::TAG_CONTACTS
=> array(
95 'title' => ts('Tag Contacts (assign tags)'),
96 'class' => 'CRM_Contact_Form_Task_AddToTag',
98 self
::REMOVE_TAGS
=> array(
99 'title' => ts('Untag Contacts (remove tags)'),
100 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
102 self
::EXPORT_CONTACTS
=> array(
103 'title' => ts('Export Contacts'),
105 'CRM_Export_Form_Select',
106 'CRM_Export_Form_Map',
110 self
::EMAIL_CONTACTS
=> array(
111 'title' => ts('Send Email to Contacts'),
112 'class' => 'CRM_Contact_Form_Task_Email',
115 self
::SMS_CONTACTS
=> array(
116 'title' => ts('Send SMS to Contacts'),
117 'class' => 'CRM_Contact_Form_Task_SMS',
120 self
::DELETE_CONTACTS
=> array(
121 'title' => ts('Delete Contacts'),
122 'class' => 'CRM_Contact_Form_Task_Delete',
125 self
::RECORD_CONTACTS
=> array(
126 'title' => ts('Record Activity for Contacts'),
127 'class' => 'CRM_Activity_Form_Activity',
129 self
::SAVE_SEARCH
=> array(
130 'title' => ts('New Smart Group'),
131 'class' => 'CRM_Contact_Form_Task_SaveSearch',
134 self
::SAVE_SEARCH_UPDATE
=> array(
135 'title' => ts('Update Smart Group'),
136 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
139 self
::PRINT_CONTACTS
=> array(
140 'title' => ts('Print Selected Rows'),
141 'class' => 'CRM_Contact_Form_Task_Print',
144 self
::LABEL_CONTACTS
=> array(
145 'title' => ts('Mailing Labels'),
146 'class' => 'CRM_Contact_Form_Task_Label',
149 self
::BATCH_UPDATE
=> array(
150 'title' => ts('Batch Update via Profile'),
152 'CRM_Contact_Form_Task_PickProfile',
153 'CRM_Contact_Form_Task_Batch',
157 self
::PRINT_FOR_CONTACTS
=> array(
158 'title' => ts('Print PDF Letter for Contacts'),
159 'class' => 'CRM_Contact_Form_Task_PDF',
162 self
::EMAIL_UNHOLD
=> array(
163 'title' => ts('Unhold Emails'),
164 'class' => 'CRM_Contact_Form_Task_Unhold',
166 self
::COMMUNICATION_PREFS
=> array(
167 'title' => ts('Alter Contact Communication Preferences'),
168 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
170 self
::RESTORE
=> array(
171 'title' => ts('Restore Contacts'),
172 'class' => 'CRM_Contact_Form_Task_Delete',
175 self
::DELETE_PERMANENTLY
=> array(
176 'title' => ts('Delete Permanently'),
177 'class' => 'CRM_Contact_Form_Task_Delete',
182 if (CRM_Contact_BAO_ContactType
::isActive('Household')) {
183 $label = CRM_Contact_BAO_ContactType
::getLabel('Household');
184 self
::$_tasks[self
::HOUSEHOLD_CONTACTS
] = array(
185 'title' => ts('Add Contacts to %1',
188 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
192 if (CRM_Contact_BAO_ContactType
::isActive('Organization')) {
193 $label = CRM_Contact_BAO_ContactType
::getLabel('Organization');
194 self
::$_tasks[self
::ORGANIZATION_CONTACTS
] = array(
195 'title' => ts('Add Contacts to %1',
198 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
202 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
203 self
::$_tasks[self
::MERGE_CONTACTS
] = array(
204 'title' => ts('Merge Contacts'),
205 'class' => 'CRM_Contact_Form_Task_Merge',
210 //CRM-4418, check for delete
211 if (!CRM_Core_Permission
::check('delete contacts')) {
212 unset(self
::$_tasks[self
::DELETE_CONTACTS
]);
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();
219 if ($config->mapProvider
&&
220 ($config->mapProvider
== 'Google' ||
221 ($config->mapProvider
== 'OpenStreetMaps' ||
222 $config->geoProvider
== 'Google'
226 self
::$_tasks[self
::MAP_CONTACTS
] = array(
227 'title' => ts('Map Contacts'),
228 'class' => 'CRM_Contact_Form_Task_Map',
233 if (CRM_Core_Permission
::access('CiviEvent')) {
234 self
::$_tasks[self
::ADD_EVENT
] = array(
235 'title' => ts('Add Contacts to Event'),
236 'class' => 'CRM_Event_Form_Participant',
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'),
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',
254 elseif (CRM_Mailing_Info
::workflowEnabled() &&
255 CRM_Core_Permission
::check('create mailings')
257 self
::$_tasks[self
::CREATE_MAILING
] = array(
258 'title' => ts('Create a Mass Mailing'),
260 'CRM_Mailing_Form_Group',
261 'CRM_Mailing_Form_Settings',
262 'CRM_Mailing_Form_Upload',
263 'CRM_Mailing_Form_Test',
270 if (CRM_Core_Permission
::access('CiviMail')
271 ||
(CRM_Mailing_Info
::workflowEnabled() && CRM_Core_Permission
::check('create mailings'))
273 self
::$_tasks[self
::CREATE_MAILING
] = array(
274 'title' => ts('Schedule/Send a Mass Mailing'),
275 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
281 self
::$_tasks +
= CRM_Core_Component
::taskList();
283 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
285 asort(self
::$_tasks);
290 * These tasks are the core set of tasks that the user can perform
291 * on a contact / group of contacts
294 * the set of tasks for a group of contacts
296 public static function &taskTitles() {
300 foreach (self
::$_tasks as $id => $value) {
301 $titles[$id] = $value['title'];
304 // hack unset update saved search
305 unset($titles[self
::SAVE_SEARCH_UPDATE
]);
307 if (!CRM_Utils_Mail
::validOutBoundMail()) {
308 unset($titles[self
::EMAIL_CONTACTS
]);
309 unset($titles[self
::CREATE_MAILING
]);
313 if (!CRM_Core_Permission
::check('access deleted contacts') ||
314 !CRM_Core_Permission
::check('delete contacts')
316 unset($titles[self
::DELETE_PERMANENTLY
]);
323 * Show tasks selectively based on the permission level
326 * @param int $permission
327 * @param bool $deletedContacts
328 * Are these tasks for operating on deleted contacts?.
331 * set of tasks that are valid for the user
333 public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) {
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'];
344 elseif ($permission == CRM_Core_Permission
::EDIT
) {
345 $tasks = self
::taskTitles();
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'],
354 if (isset(self
::$_tasks[self
::MAP_CONTACTS
]) &&
355 !empty(self
::$_tasks[self
::MAP_CONTACTS
]['title'])
357 $tasks[self
::MAP_CONTACTS
] = self
::$_tasks[self
::MAP_CONTACTS
]['title'];
360 if (isset(self
::$_tasks[self
::CREATE_MAILING
]) &&
361 !empty(self
::$_tasks[self
::CREATE_MAILING
]['title'])
363 $tasks[self
::CREATE_MAILING
] = self
::$_tasks[self
::CREATE_MAILING
]['title'];
370 * These tasks get added based on the context the user is in.
373 * the set of optional tasks for a group of contacts
375 public static function &optionalTaskTitle() {
377 self
::SAVE_SEARCH_UPDATE
=> self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'],
387 public static function getTask($value) {
390 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
391 // make it the print task by default
392 $value = self
::PRINT_CONTACTS
;
395 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
396 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),