3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
37 class CRM_Contact_Task
{
47 HOUSEHOLD_CONTACTS
= 9,
48 ORGANIZATION_CONTACTS
= 10,
52 SAVE_SEARCH_UPDATE
= 14,
57 PRINT_FOR_CONTACTS
= 19,
62 DELETE_PERMANENTLY
= 24,
63 COMMUNICATION_PREFS
= 25;
70 static $_tasks = NULL;
73 * The optional task array
77 static $_optionalTasks = NULL;
79 public static function initTasks() {
81 self
::$_tasks = array(
82 self
::GROUP_CONTACTS
=> array(
83 'title' => ts('Group - add contacts'),
84 'class' => 'CRM_Contact_Form_Task_AddToGroup',
86 self
::REMOVE_CONTACTS
=> array(
87 'title' => ts('Group - remove contacts'),
88 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
90 self
::TAG_CONTACTS
=> array(
91 'title' => ts('Tag - add to contacts'),
92 'class' => 'CRM_Contact_Form_Task_AddToTag',
94 self
::REMOVE_TAGS
=> array(
95 'title' => ts('Tag - remove from contacts'),
96 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
98 self
::EXPORT_CONTACTS
=> array(
99 'title' => ts('Export contacts'),
101 'CRM_Export_Form_Select',
102 'CRM_Export_Form_Map',
106 self
::EMAIL_CONTACTS
=> array(
107 'title' => ts('Email - send now (to 50 or less)'),
108 'class' => 'CRM_Contact_Form_Task_Email',
111 self
::DELETE_CONTACTS
=> array(
112 'title' => ts('Delete contacts'),
113 'class' => 'CRM_Contact_Form_Task_Delete',
116 self
::RECORD_CONTACTS
=> array(
117 'title' => ts('Add activity'),
118 'class' => 'CRM_Activity_Form_Activity',
120 self
::SAVE_SEARCH
=> array(
121 'title' => ts('Group - create smart group'),
122 'class' => 'CRM_Contact_Form_Task_SaveSearch',
125 self
::SAVE_SEARCH_UPDATE
=> array(
126 'title' => ts('Group - update smart group'),
127 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
130 self
::PRINT_CONTACTS
=> array(
131 'title' => ts('Print selected rows'),
132 'class' => 'CRM_Contact_Form_Task_Print',
135 self
::LABEL_CONTACTS
=> array(
136 'title' => ts('Mailing labels - print'),
137 'class' => 'CRM_Contact_Form_Task_Label',
140 self
::BATCH_UPDATE
=> array(
141 'title' => ts('Update multiple contacts'),
143 'CRM_Contact_Form_Task_PickProfile',
144 'CRM_Contact_Form_Task_Batch',
148 self
::PRINT_FOR_CONTACTS
=> array(
149 'title' => ts('Print/merge document'),
150 'class' => 'CRM_Contact_Form_Task_PDF',
153 self
::EMAIL_UNHOLD
=> array(
154 'title' => ts('Email - unhold addresses'),
155 'class' => 'CRM_Contact_Form_Task_Unhold',
157 self
::COMMUNICATION_PREFS
=> array(
158 'title' => ts('Communication preferences - alter'),
159 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
161 self
::RESTORE
=> array(
162 'title' => ts('Restore contacts from trash'),
163 'class' => 'CRM_Contact_Form_Task_Delete',
166 self
::DELETE_PERMANENTLY
=> array(
167 'title' => ts('Delete permanently'),
168 'class' => 'CRM_Contact_Form_Task_Delete',
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(
177 'title' => ts('SMS - schedule/send'),
178 'class' => 'CRM_Contact_Form_Task_SMS',
183 if (CRM_Contact_BAO_ContactType
::isActive('Household')) {
184 $label = CRM_Contact_BAO_ContactType
::getLabel('household');
185 self
::$_tasks[self
::HOUSEHOLD_CONTACTS
] = array(
186 'title' => ts('Add relationship - to %1',
189 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
193 if (CRM_Contact_BAO_ContactType
::isActive('Organization')) {
194 $label = CRM_Contact_BAO_ContactType
::getLabel('organization');
195 self
::$_tasks[self
::ORGANIZATION_CONTACTS
] = array(
196 'title' => ts('Add relationship - to %1',
199 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
203 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
204 self
::$_tasks[self
::MERGE_CONTACTS
] = array(
205 'title' => ts('Merge contacts'),
206 'class' => 'CRM_Contact_Form_Task_Merge',
211 //CRM-4418, check for delete
212 if (!CRM_Core_Permission
::check('delete contacts')) {
213 unset(self
::$_tasks[self
::DELETE_CONTACTS
]);
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();
220 if ($config->mapProvider
&&
221 ($config->mapProvider
== 'Google' ||
222 ($config->mapProvider
== 'OpenStreetMaps' ||
223 $config->geoProvider
== 'Google'
227 self
::$_tasks[self
::MAP_CONTACTS
] = array(
228 'title' => ts('Map contacts'),
229 'class' => 'CRM_Contact_Form_Task_Map',
234 if (CRM_Core_Permission
::access('CiviEvent')) {
235 self
::$_tasks[self
::ADD_EVENT
] = array(
236 'title' => ts('Register participants for event'),
237 'class' => 'CRM_Event_Form_Participant',
241 if (CRM_Core_Permission
::access('CiviMail')
242 ||
(CRM_Mailing_Info
::workflowEnabled() && CRM_Core_Permission
::check('create mailings'))
244 self
::$_tasks[self
::CREATE_MAILING
] = array(
245 'title' => ts('Email - schedule/send via CiviMail'),
246 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
251 self
::$_tasks +
= CRM_Core_Component
::taskList();
253 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
259 * These tasks are the core set of tasks that the user can perform
260 * on a contact / group of contacts
263 * the set of tasks for a group of contacts
265 public static function &taskTitles() {
269 foreach (self
::$_tasks as $id => $value) {
270 $titles[$id] = $value['title'];
273 // hack unset update saved search
274 unset($titles[self
::SAVE_SEARCH_UPDATE
]);
276 if (!CRM_Utils_Mail
::validOutBoundMail()) {
277 unset($titles[self
::EMAIL_CONTACTS
]);
278 unset($titles[self
::CREATE_MAILING
]);
282 if (!CRM_Core_Permission
::check('access deleted contacts') ||
283 !CRM_Core_Permission
::check('delete contacts')
285 unset($titles[self
::DELETE_PERMANENTLY
]);
291 * Show tasks selectively based on the permission level
294 * @param int $permission
295 * @param bool $deletedContacts
296 * Are these tasks for operating on deleted contacts?.
299 * set of tasks that are valid for the user
301 public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) {
304 if ($deletedContacts) {
305 if (CRM_Core_Permission
::check('access deleted contacts')) {
306 $tasks[self
::RESTORE
] = self
::$_tasks[self
::RESTORE
]['title'];
307 if (CRM_Core_Permission
::check('delete contacts')) {
308 $tasks[self
::DELETE_PERMANENTLY
] = self
::$_tasks[self
::DELETE_PERMANENTLY
]['title'];
312 elseif ($permission == CRM_Core_Permission
::EDIT
) {
313 $tasks = self
::taskTitles();
317 self
::EXPORT_CONTACTS
=> self
::$_tasks[self
::EXPORT_CONTACTS
]['title'],
318 self
::EMAIL_CONTACTS
=> self
::$_tasks[self
::EMAIL_CONTACTS
]['title'],
319 self
::LABEL_CONTACTS
=> self
::$_tasks[self
::LABEL_CONTACTS
]['title'],
322 if (isset(self
::$_tasks[self
::MAP_CONTACTS
]) &&
323 !empty(self
::$_tasks[self
::MAP_CONTACTS
]['title'])
325 $tasks[self
::MAP_CONTACTS
] = self
::$_tasks[self
::MAP_CONTACTS
]['title'];
328 if (isset(self
::$_tasks[self
::CREATE_MAILING
]) &&
329 !empty(self
::$_tasks[self
::CREATE_MAILING
]['title'])
331 $tasks[self
::CREATE_MAILING
] = self
::$_tasks[self
::CREATE_MAILING
]['title'];
338 * These tasks get added based on the context the user is in.
341 * the set of optional tasks for a group of contacts
343 public static function &optionalTaskTitle() {
345 self
::SAVE_SEARCH_UPDATE
=> self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'],
355 public static function getTask($value) {
358 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
359 // make it the print task by default
360 $value = self
::PRINT_CONTACTS
;
363 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
364 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),