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,
64 INDIVIDUAL_CONTACTS
= 26,
72 static $_tasks = NULL;
75 * The optional task array
79 static $_optionalTasks = NULL;
81 public static function tasks() {
86 public static function initTasks() {
88 self
::$_tasks = array(
89 self
::GROUP_CONTACTS
=> array(
90 'title' => ts('Group - add contacts'),
91 'class' => 'CRM_Contact_Form_Task_AddToGroup',
92 'url' => 'civicrm/task/add-to-group',
94 self
::REMOVE_CONTACTS
=> array(
95 'title' => ts('Group - remove contacts'),
96 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
97 'url' => 'civicrm/task/remove-from-group',
99 self
::TAG_CONTACTS
=> array(
100 'title' => ts('Tag - add to contacts'),
101 'class' => 'CRM_Contact_Form_Task_AddToTag',
102 'url' => 'civicrm/task/add-to-tag',
104 self
::REMOVE_TAGS
=> array(
105 'title' => ts('Tag - remove from contacts'),
106 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
107 'url' => 'civicrm/task/remove-from-tag',
109 self
::EXPORT_CONTACTS
=> array(
110 'title' => ts('Export contacts'),
112 'CRM_Export_Form_Select',
113 'CRM_Export_Form_Map',
117 self
::EMAIL_CONTACTS
=> array(
118 'title' => ts('Email - send now (to %1 or less)', array(1 => Civi
::settings()->get('simple_mail_limit'))),
119 'class' => 'CRM_Contact_Form_Task_Email',
121 'url' => 'civicrm/task/send-email',
123 self
::DELETE_CONTACTS
=> array(
124 'title' => ts('Delete contacts'),
125 'class' => 'CRM_Contact_Form_Task_Delete',
127 'url' => 'civicrm/task/delete-contact',
129 self
::RECORD_CONTACTS
=> array(
130 'title' => ts('Add activity'),
131 'class' => 'CRM_Activity_Form_Activity',
133 self
::SAVE_SEARCH
=> array(
134 'title' => ts('Group - create smart group'),
135 'class' => 'CRM_Contact_Form_Task_SaveSearch',
138 self
::SAVE_SEARCH_UPDATE
=> array(
139 'title' => ts('Group - update smart group'),
140 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
143 self
::PRINT_CONTACTS
=> array(
144 'title' => ts('Print selected rows'),
145 'class' => 'CRM_Contact_Form_Task_Print',
148 self
::LABEL_CONTACTS
=> array(
149 'title' => ts('Mailing labels - print'),
150 'class' => 'CRM_Contact_Form_Task_Label',
152 'url' => 'civicrm/task/make-mailing-label',
154 self
::BATCH_UPDATE
=> array(
155 'title' => ts('Update multiple contacts'),
157 'CRM_Contact_Form_Task_PickProfile',
158 'CRM_Contact_Form_Task_Batch',
161 'url' => 'civicrm/task/pick-profile',
163 self
::PRINT_FOR_CONTACTS
=> array(
164 'title' => ts('Print/merge document'),
165 'class' => 'CRM_Contact_Form_Task_PDF',
167 'url' => 'civicrm/task/print-document',
169 self
::EMAIL_UNHOLD
=> array(
170 'title' => ts('Email - unhold addresses'),
171 'class' => 'CRM_Contact_Form_Task_Unhold',
172 'url' => 'civicrm/task/unhold-email',
174 self
::COMMUNICATION_PREFS
=> array(
175 'title' => ts('Communication preferences - alter'),
176 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
177 'url' => 'civicrm/task/alter-contact-preference',
179 self
::RESTORE
=> array(
180 'title' => ts('Restore contacts from trash'),
181 'class' => 'CRM_Contact_Form_Task_Delete',
184 self
::DELETE_PERMANENTLY
=> array(
185 'title' => ts('Delete permanently'),
186 'class' => 'CRM_Contact_Form_Task_Delete',
191 //CRM-16329, if SMS provider is configured show sms action.
192 $providersCount = CRM_SMS_BAO_Provider
::activeProviderCount();
193 if ($providersCount) {
194 self
::$_tasks[self
::SMS_CONTACTS
] = array(
195 'title' => ts('SMS - schedule/send'),
196 'class' => 'CRM_Contact_Form_Task_SMS',
201 if (CRM_Contact_BAO_ContactType
::isActive('Individual')) {
202 $label = CRM_Contact_BAO_ContactType
::getLabel('individual');
203 self
::$_tasks[self
::INDIVIDUAL_CONTACTS
] = array(
204 'title' => ts('Add relationship - to %1',
207 'class' => 'CRM_Contact_Form_Task_AddToIndividual',
211 if (CRM_Contact_BAO_ContactType
::isActive('Household')) {
212 $label = CRM_Contact_BAO_ContactType
::getLabel('household');
213 self
::$_tasks[self
::HOUSEHOLD_CONTACTS
] = array(
214 'title' => ts('Add relationship - to %1',
217 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
221 if (CRM_Contact_BAO_ContactType
::isActive('Organization')) {
222 $label = CRM_Contact_BAO_ContactType
::getLabel('organization');
223 self
::$_tasks[self
::ORGANIZATION_CONTACTS
] = array(
224 'title' => ts('Add relationship - to %1',
227 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
231 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
232 self
::$_tasks[self
::MERGE_CONTACTS
] = array(
233 'title' => ts('Merge contacts'),
234 'class' => 'CRM_Contact_Form_Task_Merge',
239 //CRM-4418, check for delete
240 if (!CRM_Core_Permission
::check('delete contacts')) {
241 unset(self
::$_tasks[self
::DELETE_CONTACTS
]);
244 //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
245 // should fix this to be more flexible as providers are added ??
246 $config = CRM_Core_Config
::singleton();
248 if ($config->mapProvider
&&
249 ($config->mapProvider
== 'Google' ||
250 ($config->mapProvider
== 'OpenStreetMaps' ||
251 $config->geoProvider
== 'Google'
255 self
::$_tasks[self
::MAP_CONTACTS
] = array(
256 'title' => ts('Map contacts'),
257 'class' => 'CRM_Contact_Form_Task_Map',
262 if (CRM_Core_Permission
::access('CiviEvent')) {
263 self
::$_tasks[self
::ADD_EVENT
] = array(
264 'title' => ts('Register participants for event'),
265 'class' => 'CRM_Event_Form_Participant',
269 if (CRM_Core_Permission
::access('CiviMail')
270 ||
(CRM_Mailing_Info
::workflowEnabled() && CRM_Core_Permission
::check('create mailings'))
272 self
::$_tasks[self
::CREATE_MAILING
] = array(
273 'title' => ts('Email - schedule/send via CiviMail'),
274 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
279 if (CRM_Core_Permission
::access('CiviCase')) {
280 self
::$_tasks[self
::ADD_TO_CASE
] = array(
281 'title' => 'Add to case as role',
282 'class' => 'CRM_Case_Form_AddToCaseAsRole',
287 self
::$_tasks +
= CRM_Core_Component
::taskList();
289 CRM_Utils_Hook
::searchTasks('contact', self
::$_tasks);
294 * These tasks are the core set of tasks that the user can perform
295 * on a contact / group of contacts
298 * the set of tasks for a group of contacts
300 public static function &taskTitles() {
304 foreach (self
::$_tasks as $id => $value) {
305 $titles[$id] = $value['title'];
308 // hack unset update saved search
309 unset($titles[self
::SAVE_SEARCH_UPDATE
]);
311 if (!CRM_Utils_Mail
::validOutBoundMail()) {
312 unset($titles[self
::EMAIL_CONTACTS
]);
313 unset($titles[self
::CREATE_MAILING
]);
317 if (!CRM_Core_Permission
::check('access deleted contacts') ||
318 !CRM_Core_Permission
::check('delete contacts')
320 unset($titles[self
::DELETE_PERMANENTLY
]);
326 * Show tasks selectively based on the permission level
329 * @param int $permission
330 * @param bool $deletedContacts
331 * Are these tasks for operating on deleted contacts?.
334 * set of tasks that are valid for the user
336 public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) {
339 if ($deletedContacts) {
340 if (CRM_Core_Permission
::check('access deleted contacts')) {
341 $tasks[self
::RESTORE
] = self
::$_tasks[self
::RESTORE
]['title'];
342 if (CRM_Core_Permission
::check('delete contacts')) {
343 $tasks[self
::DELETE_PERMANENTLY
] = self
::$_tasks[self
::DELETE_PERMANENTLY
]['title'];
347 elseif ($permission == CRM_Core_Permission
::EDIT
) {
348 $tasks = self
::taskTitles();
352 self
::EXPORT_CONTACTS
=> self
::$_tasks[self
::EXPORT_CONTACTS
]['title'],
353 self
::EMAIL_CONTACTS
=> self
::$_tasks[self
::EMAIL_CONTACTS
]['title'],
354 self
::LABEL_CONTACTS
=> self
::$_tasks[self
::LABEL_CONTACTS
]['title'],
357 if (isset(self
::$_tasks[self
::MAP_CONTACTS
]) &&
358 !empty(self
::$_tasks[self
::MAP_CONTACTS
]['title'])
360 $tasks[self
::MAP_CONTACTS
] = self
::$_tasks[self
::MAP_CONTACTS
]['title'];
363 if (isset(self
::$_tasks[self
::CREATE_MAILING
]) &&
364 !empty(self
::$_tasks[self
::CREATE_MAILING
]['title'])
366 $tasks[self
::CREATE_MAILING
] = self
::$_tasks[self
::CREATE_MAILING
]['title'];
373 * These tasks get added based on the context the user is in.
376 * the set of optional tasks for a group of contacts
378 public static function &optionalTaskTitle() {
380 self
::SAVE_SEARCH_UPDATE
=> self
::$_tasks[self
::SAVE_SEARCH_UPDATE
]['title'],
390 public static function getTask($value) {
393 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
394 // make it the print task by default
395 $value = self
::PRINT_CONTACTS
;
398 CRM_Utils_Array
::value('class', self
::$_tasks[$value]),
399 CRM_Utils_Array
::value('result', self
::$_tasks[$value]),
404 * Function to return the task information on basis of provided task's form name
406 * @param string $className
410 public static function getTaskAndTitleByClass($className) {
413 foreach (self
::$_tasks as $task => $value) {
414 if ((!empty($value['url']) ||
$task == self
::EXPORT_CONTACTS
) && (
415 (is_array($value['class']) && in_array($className, $value['class'])) ||
416 ($value['class'] == $className)
421 CRM_Utils_Array
::value('title', $value),